//
//  YDVistorView.swift
//  YDWeibo01
//
//  Created by suibian on 16/8/9.
//  Copyright © 2016年 iitcast. All rights reserved.
//

import UIKit
import SnapKit
class YDVistorView: UIView {
//    声明一个闭包
    var closure:(()->())?
    
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
//    监听按钮点击的方法
    @objc private func buttonClick(){
//        执行闭包
        closure?()

        
    
    
    }
    
//    提供外界调用的方法
    func setupVisitorViewInfo(imageName:String?,title:String?){
//    代表设置的是发现 消息 我的界面(6个图是以home视图设置的 home传nil 如果不为nil 就是其他三个界面)
        if let img = imageName,tlt = title{
            
        houseImageView.image = UIImage(named: img)
            messageLabel.text = tlt
//        隐藏圈圈
            circleImageView.hidden = true
            
        }else{
//        代表为首页
        }
    
    }
//    设置圆圈动画
    func setupAni(){
    let anim = CABasicAnimation(keyPath: "transform.rotation")
//        设置tovalue
        anim.toValue = M_PI * 2
//        设置动画时间
        anim.duration = 10
        
//        设置循环次数
        anim.repeatCount = MAXFLOAT
//        如果控制器退到后台 或者切换页面 默认动画会移除
        
        anim.removedOnCompletion = false
        
        
    
    }
    
    
//    设置视图
    private func setupUI(){
        
    
    backgroundColor = RGB(237,green: 237,blue: 237)
        
//        01添加控件
        
        addSubview(circleImageView)
        addSubview(maskImageView)
        addSubview(houseImageView)
        addSubview(messageLabel)
        addSubview(loginButton)
        addSubview(RegisterButton)
        
//        02添加约束
        circleImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
            
        }
    
        maskImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
        }
        
        houseImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
        }
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(maskImageView.snp_bottom).offset(16)
            make.height.equalTo(36)
            make.centerX.equalTo(self)
        }
        loginButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(messageLabel)
            make.top.equalTo(messageLabel.snp_bottom).offset(16)
            make.size.equalTo(CGSize(width: 100, height: 36))
            
        RegisterButton.snp_makeConstraints { (make) -> Void in
                make.trailing.equalTo(messageLabel)
                make.top.equalTo(messageLabel.snp_bottom).offset(16)
                make.size.equalTo(loginButton)
            }

        }
    }
    
    
//    懒加载控件
//    图片用自定义分类的方法来加载
//    圆圈
    
    private lazy var circleImageView:UIImageView = UIImageView(imageName: "visitordiscover_feed_image_smallicon")
//    遮挡
    private lazy var maskImageView:UIImageView = UIImageView(imageName: "visitordiscover_feed_mask_smallicon")
//    房子
    private lazy var houseImageView:UIImageView = UIImageView(imageName: "visitordiscover_feed_image_house")
//    文字
    private lazy var messageLabel:UILabel = {
    let lable = UILabel()
        lable.textColor = UIColor.orangeColor()
        lable.font = UIFont.systemFontOfSize(15)
        lable.numberOfLines = 0
        lable.textAlignment = .Center
        lable.text = "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜"
//        设置最大显示宽度
        lable.preferredMaxLayoutWidth = 240
        
        
        
        return lable
    }()
    
    private lazy var loginButton:UIButton = {
    
        let button = UIButton()
//       添加点击事件
        button.addTarget(self, action: "buttonClick", forControlEvents: UIControlEvents.TouchUpInside)
        button.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        
        button.setTitle("注册", forState: UIControlState.Normal)
        button.setTitleColor(AppThemeColor, forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        return button
    }()
    private lazy var RegisterButton:UIButton = {
        
        let button = UIButton()
//        添加点击事件
        button.addTarget(self, action: "buttonClick", forControlEvents: UIControlEvents.TouchUpInside)

        button.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        button.setTitle("登录", forState: UIControlState.Normal)
        button.setTitleColor(AppThemeColor, forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        return button
    }()

    
}
